package com.train.system.facade;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.group.AddGroup;
import com.train.common.group.EditGroup;
import com.train.common.group.QueryGroup;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.system.dto.carriage.TrainCarriageAddOrEditDTO;
import com.train.system.dto.carriage.TrainCarriageDTO;
import com.train.system.dto.carriage.TrainCarriagePageDTO;
import com.train.system.req.carriage.TrainCarriageAddOrEditReq;
import com.train.system.req.carriage.TrainCarriageReq;
import com.train.system.req.carriage.TrainCarriagePageReq;
import com.train.system.resp.carriage.TrainCarriageDetailResp;
import com.train.system.resp.carriage.TrainCarriagePageResp;
import com.train.system.service.TrainCarriageService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * trainCarriage Facade 实现类
 * @author baitiaojun
 * @createDate 2025-02-20 18:52:37
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("train-carriage")
public class TrainCarriageFacade {

    private final TrainCarriageService trainCarriageService;

    @PostMapping("page")
    public CommonResp pageList(@RequestBody @Validated(QueryGroup.class) TrainCarriagePageReq req) {
        TrainCarriagePageDTO trainCarriagePageDTO = BeanUtil.copyProperties(req, TrainCarriagePageDTO.class);
        PageResp<TrainCarriagePageResp> pageResp = trainCarriageService.pageList(trainCarriagePageDTO);
        return CommonResp.ok(pageResp);
    }

    @PostMapping("add")
    public CommonResp add(@RequestBody @Validated(AddGroup.class) TrainCarriageAddOrEditReq req) {
        TrainCarriageAddOrEditDTO trainCarriageAddOrEditDTO = BeanUtil.copyProperties(req, TrainCarriageAddOrEditDTO.class);
        trainCarriageService.addOrEditTrainCarriage(trainCarriageAddOrEditDTO);
        return CommonResp.ok();
    }

    @PostMapping("edit")
    public CommonResp edit(@RequestBody @Validated(EditGroup.class) TrainCarriageAddOrEditReq req) {
        TrainCarriageAddOrEditDTO trainCarriageAddOrEditDTO = BeanUtil.copyProperties(req, TrainCarriageAddOrEditDTO.class);
        trainCarriageService.addOrEditTrainCarriage(trainCarriageAddOrEditDTO);
        return CommonResp.ok();
    }

    @DeleteMapping("remove/{id}")
    public CommonResp delete(@PathVariable("id") Long id) {
        trainCarriageService.remove(id);
        return CommonResp.ok();
    }

    @PostMapping("one")
    public CommonResp getOne(@RequestBody @Validated TrainCarriageReq req) {
        TrainCarriageDTO trainCarriageDTO = BeanUtil.copyProperties(req, TrainCarriageDTO.class);
        TrainCarriageDetailResp resp = trainCarriageService.getOne(trainCarriageDTO);
        return CommonResp.ok(resp);
    }
}
